﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using SharpPcap;
using SharpPcap.Packets;

namespace PacketHandler
{
    public class BlizzardPacket
    {
        public enum GamePacketConstants : byte
        {
            BNET_PROTOCOL = 0xff,
            W3GS_PROTOCOL = 0xf7
        }

        protected Packet GamePacket = null;

        public BlizzardPacket(Packet GamePacket)
        {
            this.GamePacket = GamePacket;
        }

        public GamePacketConstants PacketProtocol
        {
            get
            {
                GamePacketConstants value = (GamePacketConstants)GamePacket.Data[0];

                return value;
            }
        }

        public byte PacketCommand
        {
            get
            {
                if (GamePacket is TCPPacket)
                    return ((TCPPacket)GamePacket).Data[1];
                else
                    return ((UDPPacket)GamePacket).Data[1];
            }
        }

        public int PayloadSize
        {
            get { return BitConverter.ToInt16(Payload, 2); }
        }


        public byte[] Payload
        {
            get
            {
                if (GamePacket is TCPPacket)
                    return ((TCPPacket)GamePacket).Data;
                else
                    return ((UDPPacket)GamePacket).Data;
            }
        }

        public Packet RawPacket
        {
            get { return GamePacket; }
        }

        public bool IsBlizzardPacket
        {
            get
            {
                foreach (GamePacketConstants g in Enum.GetValues(typeof(GamePacketConstants)))
                {
                    if (PacketProtocol == g)
                        return true;
                }

                return false;
            }
        }



    }
}
